const {Book} = require("../../models/Books");

module.exports = async (req, res) => {
  const searchName = req.query.searchName;
  //转化为正则表达式
  var re =eval("/" + searchName + "/") 
    try{
      //分别根据ISBN、书名、作者查询
    const result1 = await Book.find({ISBN:re}).lean();
    const result2 = await Book.find({title:re}).lean();
    const result3 = await Book.find({author:re}).lean();

    var result = [];
    result = result.concat(result1);
    result = result.concat(result2);
    result = result.concat(result3);

       res.send({errCode:"1",msg:"请求成功",data:{searchInfo:result}})
    }catch(e){
      console.log(e)
        res.status(500).send({errCode:"1",msg:"服务器错误"})
    }
}